package com.shuoyue.ycgk.ui.estimate;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.QuestionParent;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;

public interface EstimateCheckAllContract {
    interface View extends BaseView {

        void setQuestions(List<QuestionParent> questions);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getQuestions(int pagerId,int evaId) {
            apply(model.getEstimateQuestion(pagerId,evaId))
                    .subscribe(new ApiSubscriber<Optional<List<QuestionParent>>>(mView,
                            this, true) {
                        @Override
                        public void onNext(Optional<List<QuestionParent>> specialPagerOptional) {
                            super.onNext(specialPagerOptional);
                            mView.setQuestions(specialPagerOptional.getIncludeNull());
                        }
                    });
        }


    }

    class Model extends BaseModel {
        Observable<BaseResult<List<QuestionParent>>> getEstimateQuestion(int pagerId,int evaId) {
            return RetrofitClient.getInstance().getApi().getEstimateQuestionsTb(pagerId,evaId);
        }
    }
}
